home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BMUG Revelations
/
BMUG Revelations.toast
/
Utilities
/
Text and Speech
/
BBEdit 2.2.2
/
BBEdit Extensions
/
Sources
/
CopyContaining.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-09
|
2KB
|
138 lines
#include <SetupA4.h>
#include "ExternalInterface.h"
#include "DialogUtilities.h"
static void maintain_buttons(DialogPtr d)
{
Boolean enable;
Str255 s;
ReadStrItem(d, 4, s);
enable = (s[0] != 0);
if (enable != TestDlgCtl(d, 1))
XAbleDlgCtl(d, 1, enable);
}
pascal Boolean (*std_filter)(DialogPtr d, EventRecord *event, short *item);
static pascal Boolean filter(DialogPtr d, EventRecord *event, short *item)
{
Boolean result;
SetUpA4();
maintain_buttons(d);
result = std_filter(d, event, item);
RestoreA4();
return result;
}
pascal void main(ExternalCallbackBlock *callbacks, WindowPtr w)
{
long line_count;
long line;
long line_start;
long line_end;
Handle text;
Handle copy;
Boolean found;
Str255 search_str;
Boolean case_sensitive;
DialogPtr d;
GrafPtr save_port;
short item;
long offset;
OSErr err;
RememberA0();
SetUpA4();
case_sensitive = FALSE;
GetPort(&save_port);
d = callbacks->CenterDialog(128);
SetPort(d);
std_filter = callbacks->StandardFilter;
do {
ModalDialog(filter, &item);
if (item == 3)
{
case_sensitive = ! case_sensitive;
SetDlgCtl(d, item, case_sensitive);
}
} while ((item != 1) && (item != 2));
ReadStrItem(d, 4, search_str);
DisposDialog(d);
SetPort(save_port);
if (item == 1)
{
line_count = callbacks->GetLastLine();
text = callbacks->GetWindowContents(w);
found = FALSE;
copy = NewHandle(0);
err = noErr;
for (line = 0; line < line_count; line++)
{
line_start = callbacks->GetLinePos(line);
line_end = callbacks->GetLineEnd(line_start);
offset = callbacks->FindPattern(*text, line_end, line_start,
(char *)&search_str[1], search_str[0],
case_sensitive);
if (offset >= 0)
{
MoveHHi(text);
HLock(text);
err = PtrAndHand(*text + line_start, copy, line_end - line_start + 1);
HUnlock(text);
if (err)
break;
found = TRUE;
}
}
if (err)
callbacks->ReportOSError(err);
else
{
if (found)
{
HLock(copy);
ZeroScrap();
PutScrap(GetHandleSize(copy), 'TEXT', *copy);
}
else
SysBeep(2);
}
DisposHandle(copy);
}
RestoreA4();
}